'use strict';

var deviceMap = {
    bed: '床',
    wardrobe: '衣柜',
    desk: '书桌',
    wifi: '无线网络',
    washer: '洗衣机',
    waterHeater: '热水器',
    airConditioning: '空调',
    microwaveOven: '微波炉',
};

var vm = new Vue( {
    el: '#app',
    data: {
        rentType: '',
        style: '',
        orientation: '',
        area: '',
        floor: '',
        village: '',
        address: '',
        facility: '',
        traffic: '',
        region: '',
        price: 0,
        deposit: 0,
        period: "0",
        decoration: '',
        cleaning: '',
        pics: [],
        devices: [],
        currentRoom: {
            src: '',
            type: ''
        },
        showRoom: false,
        currentDevice: {
            name: '',
            description: '',
            pic: '',
        },
        showDevice: false,
    },
    created() {
        var match = /^\?id=(\d+)$/.exec(location.search);
        if (!match) {
            alert('未指定houseid');
        }
        const that = this;
        $.ajax({
            url: '/house/info',
            type: 'GET',
            data: {
                id: match[1]
            },
            success(data) {
                var res = JSON.parse(data);
                var total = res.data;
                for (var key in total) {
                    that[key] = res.data[key];
                }
                console.log(that.pics);
            }
        })
    },
    methods:{
        getDeviceName(enName) {
            return deviceMap[enName];
        },
        setCurrentFacility(device) {
            this.currentDevice = device;
            this.showDevice = true;
        },
        setCurrentRoom(room) {
            this.currentRoom = room;
            this.showRoom = true;
        },
    }

});